<template>
	<view>
		<navbox :title="parm.year+'年'+parm.mount+'月'"></navbox>
		<view style="margin-top: 190rpx;height: 180rpx;">
			<view style="text-align: center;color: #414141;font-size: 15px;">{{parm.type==='0'?'本月总支出':'本月总收入'}}</view>
			<view style="display: flex;justify-content: center;margin-top: 20rpx;">
				<u--text mode="price" :text="totalPrice" bold="true" size="23" align="center"></u--text>
			</view>
		</view>
		<view style="height: 20rpx;background-color: #f0f0f0;"></view>
		<view style="margin-left: 20rpx;margin-right: 20rpx;">
			<view style="margin-top: 10rpx;margin-bottom: 30rpx;">单笔支出排行</view>
			<view class="content" v-for="it in list" :key="it.id">
				<view>
					<view>
						<view style="margin-left: 15rpx;display: flex;align-items: center;justify-content: flex-start;">
							<u-icon :name="it.icon" color="#ffc940" size="28" top="20"></u-icon>
							<view style="margin-left: 0rpx;color: #1f1f1f;font-size: 13px;">{{it.fun}}</view>
						</view>
						<view style="margin-left: 70rpx;margin-bottom: 2rpx;">
							<u-line-progress :percentage="(it.price/totalPrice)*100" activeColor="#ff0000">
							</u-line-progress>
							<view style="display: flex;align-items: center;justify-content: space-between;">
								<view style="color: #d0d0d0;font-size: 12px;">{{it.createTime}}</view>
								<view style="">{{parm.type==='0'?'-':'+'}}{{it.price}}</view>
							</view>
						</view>
						<u-line></u-line>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import navbox from '../components/navbox/navbox.vue'
	export default {
		data() {
			return {
				parm: {
					pageSize: 12,
					pageNum: 1,
					year: 0,
					mount: 0,
					userId: uni.getStorageSync("user").id,
					type: ''
				},
				totalPrice: '',
				list: [],
				total: '',
				timer: null,
			}
		},
		onLoad(option) {
			uni.showLoading({
				title: '加载中'
			});
			this.parm.year = option.year
			this.parm.mount = option.mount
			this.totalPrice = option.total
			this.parm.type = option.type
			if (this.timer) {
				clearTimeout(this.timer); // 清除定时器  
			}
			this.getList()
		},
		onPullDownRefresh() {
			uni.showLoading({
				title: '加载中'
			});
			this.parm.pageNum = 1
			this.getList()
			this.timer =setTimeout(() => {
				uni.stopPullDownRefresh()
			}, 500)
		},
		onReachBottom() {
			this.getBottom()
		},
		methods: {
			async getBottom() {
				const that = this
				if (this.list.length < this.total) {
					this.parm.pageNum++
					uni.showLoading({
						title: '加载中'
					});
					uni.request({
						url: that.$baseurl + "/wexinLogin/famaccount/selectPaihang",
						method: 'POST',
						data: that.parm,
						success(res) {
							that.list = [...that.list, ...res.data.data.records]
						}
					})
					setTimeout(function() {
						uni.hideLoading();
					}, 800);
				}
			},
			async getList() {
				const res = await this.$myRuquest({
					url: '/wexinLogin/famaccount/selectPaihang',
					method: 'post',
					data: this.parm
				})
				this.list = res.data.data.records
				this.total = res.data.data.total
				uni.hideLoading();
			},
		},
		components: {
			"navbox": navbox,
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		height: 70rpx;
		line-height: 40rpx;
		margin-bottom: 60rpx;

		.a {
			display: flex;
			align-items: center;
			justify-content: space-between;
		}
	}
</style>
